****************************************
*Do Minorities Feel Welcome in Politics?                                  
****************************************

*Set root directory (see README.txt for folder structure) 
global root "Enter the path to where you have placed the replication here"

program drop _all
file close _all

log using "$root/Output/log", replace

*US Survey 2021

use "$root/Data/cmps2021.dta", clear 

*Data preparation

gen ethnicity= S2_Race_Prime
recode ethnicity 5=. 6=. 7=. 8=.
label define ethnicity_lab 1 "White" 2 "Latino" 3 "Black" 4 "Asian"
label values ethnicity ethnicity_lab

gen polint=-Q29+4
replace polint=polint/3
su polint
replace polint=`r(mean)' if polint==.

gen education=S13

gen age=2020-S5
su age
replace age=`r(mean)' if age==.

gen agesq=age*age

gen unemp=1 if Q814==5
recode unemp .=0 if Q814!=.
sum unemp 
replace unemp=`r(mean)' if unemp==.

gen gender=S3b
recode gender 3=. 4=.

gen welcome=1 if Q574==1
recode welcome .=0

gen welcome_parliament=-Q574+5

gen citizen=1 if Q807==1 | S7==1 | S7==3
recode citizen .=0

drop if citizen==0

drop if age<18

tab welcome ethnicity, col

tab welcome ethnicity [aw=os_weight], col

***Figure 1 (Upper left panel)***

graph bar (mean) welcome [aw=os_weight], over(ethnicity, label(labsize(small))) ytitle("")scheme(s2mono)  graphregion(fcolor(white) ilcolor(white) lcolor(white))  ///
graphregion(margin(large))  ///
title("US Survey 2021")

  graph save "${root}Output/fig1us2021.gph", replace
graph export  "${root}Output/fig1us2021.eps", replace

***Figure 2 (Upper left panel)***

reg welcome i.ethnicity [aw=os_weight], robust

estimates store results_1

coefplot results_1, drop(_cons) keep(2.ethnicity 3.ethnicity 4.ethnicity) ///
graphregion(fcolor(white))  plotregion(style(none)) ///
 graphregion(color(white)) xline(0, lcolor(grey)) xscale(range(-0.1 0)) xlabel(-0.1(0.02) 0) ///
plotregion(lcolor(black) lwidth(thin)) legend(off) ciopts(color(black)) mcolor(black) title(US Survey 2021) 

graph save "${root}Output/fig2us2021.gph", replace
graph export  "${root}Output/fig2us2021.eps", replace

***Figure A1 (Upper left panel)***

gen yesabsolutely=.
gen maybe=.
gen noprobably=.
gen noabsolutely=.

replace yesabsolutely=1 if Q574==1 
replace yesabsolutely=0 if Q574==2 | Q574==3 | Q574==4

replace maybe=1 if Q574==2
replace maybe=0 if Q574==1 | Q574==3 | Q574==4
 
replace noprobably=1 if Q574==3
replace noprobably=0 if Q574==1 | Q574==2 | Q574==4

replace noabsolutely=1 if Q574==4
replace noabsolutely=0 if Q574==1 | Q574==2 | Q574==3

graph bar (mean) yesabsolutely maybe noprobably noabsolutely, over(ethnicity, label(labsize(small))) ytitle("")scheme(s1mono)  graphregion(fcolor(white) ilcolor(white) lcolor(white))  ///
 graphregion(margin(large))  stack legend(order(1 "Yes, absolutely" 2 "Maybe" 3 "No, probably not" 4 "No, absolutely not")) ///
 title("US Survey 2021")
 
  graph save "${root}Output/figA1us2021.gph", replace
graph export  "${root}Output/figA1us2021.eps", replace

***Figure A.2  (Upper left panel)***

global controls  gender age agesq  i.education unemp polint 

reg welcome i.ethnicity $controls [aw=os_weight], robust

estimates store results_1

coefplot results_1, drop(_cons) keep(2.ethnicity 3.ethnicity 4.ethnicity) ///
graphregion(fcolor(white))  plotregion(style(none)) ///
 graphregion(color(white)) xline(0, lcolor(grey)) xscale(range(-0.1 0)) xlabel(-0.1(0.02) 0) ///
plotregion(lcolor(black) lwidth(thin)) legend(off) ciopts(color(black)) mcolor(black) title(US Survey 2021) 

graph save "${root}Output/figA2us2021.gph", replace
graph export  "${root}Output/figA2us2021.eps", replace

***Table A.1***

gen member_cs=1 if Q86==1
recode member_cs .=0 if Q86!=.

gen active_cs=1 if Q88==1
recode active_cs .=0 

gen hipol=1 if polint==1
recode hipol .=0

reg welcome i.ethnicity##hipol [aw=os_weight], robust
outreg2 using "${root}Output/tabA1.tex", replace  
reg welcome i.ethnicity##member_cs [aw=os_weight], robust
outreg2 using "${root}Output/tabA1.tex", append  
reg welcome i.ethnicity##active_cs [aw=os_weight], robust
outreg2 using "${root}Output/tabA1.tex", append  

***Table A.3  (first two columns)***

gen willingdum=1 if Q573==1
recode willingdum .=0 if Q573==2 | Q573==3

reg willingdum welcome if ethnicity!=. [aw=os_weight], robust 
outreg2 using "${root}Output/tabA3.tex", replace keep(welcome )   
reg willingdum welcome $controls if ethnicity!=. [aw=os_weight], robust 
outreg2 using "${root}Output/tabA3.tex", append   keep(welcome ) 

***Table A.5***

reg welcome i.ethnicity [aw=os_weight], robust 
outreg2 using "${root}Output/tabA5.tex", replace 
reg welcome i.ethnicity $controls [aw=os_weight] , robust 
outreg2 using "${root}Output/tabA5.tex", append  

***Table A.6***

foreach i of num 1/3 {	
gen poldisc_`i'=1 if Q281r`i'==1 
recode poldisc_`i' .=0
}

egen poldisc=rmean(poldisc_2-poldisc_3)

alpha poldisc_2-poldisc_3

foreach i of num 4/7 {
gen socdisc_`i'=1 if Q281r`i'==1 
recode socdisc_`i' .=0
}

egen socdisc=rmean(socdisc_4-socdisc_7)

alpha socdisc_4-socdisc_7

reg willingdum welcome if ethnicity!=. [aw=os_weight], robust 
outreg2 using "${root}Output/tabA6.tex", replace keep(welcome ) 
reg willingdum welcome poldisc socdisc if ethnicity!=. [aw=os_weight], robust 
outreg2 using "${root}Output/tabA6.tex", append keep(welcome poldisc socdisc)    
reg willingdum welcome poldisc socdisc $controls if ethnicity!=. [aw=os_weight], robust 
outreg2 using "${root}Output/tabA6.tex", append   keep(welcome poldisc socdisc) 

***Table A.9***

oprobit welcome_parliament i.ethnicity [aw=os_weight], robust 
outreg2 using "${root}Output/tabA9.tex", replace 
oprobit welcome_parliament i.ethnicity $controls [aw=os_weight] , robust 
outreg2 using "${root}Output/tabA9.tex", append  

***Table A.11***

oprobit welcome_parliament i.ethnicity [aw=os_weight], robust
margins, dydx(i.ethnicity) atmean
di %05.3f  el(r(b),1,5)

foreach x of numlist 5/16 {
local b`x' : di %05.3f el(r(b),1,`x')
local se`x' : di %05.4f el(r(table),2,`x')
if abs(`b`x''/`se`x'') < 1.65 local star`x' 
if abs(`b`x''/`se`x'') >= 1.65 local star`x'  \sym{*}
if abs(`b`x''/`se`x'') >= 1.96 local star`x' \sym{**}
if abs(`b`x''/`se`x'') >= 2.58 local star`x'  \sym{***}

}

oprobit welcome_parliament i.ethnicity $controls [aw=os_weight], robust
margins, dydx(i.ethnicity) atmean
di %05.3f  el(r(b),1,5)
foreach x of numlist 5/16 {
local bc`x' : di %05.3f el(r(b),1,`x')
local sec`x' : di %05.4f el(r(table),2,`x')
if abs(`bc`x''/`sec`x'') < 1.65 local star`x' 
if abs(`bc`x''/`sec`x'') >= 1.65 local starc`x'  \sym{*}
if abs(`bc`x''/`sec`x'') >= 1.96 local starc`x' \sym{**}
if abs(`bc`x''/`sec`x'') >= 2.58 local starc`x'  \sym{***}

}

file open size using "${root}Output/tabA11.tex", write replace
file write size "\begin{tabular}{lcccccc}" _n
file write size "\toprule" _n
file write size " &  \multicolumn{3}{c}{Without Controls:} & \multicolumn{3}{c}{With Controls:}\\" _n
file write size " Outcome: & Latino & Black & Asian & Latino & Black & Asian" _n
file write size "& \cline{2-7}" _n
file write size "\midrule" _n
file write size " No, absolutely not &" (`b5') "`star5'" " &  " (`b9') "`star9'" " &  " (`b13') "`star13'" " &  "  (`bc5') "`starc5'" " &  "  (`bc9') "`starc9'" " &  "  (`bc13') "`starc13'" "\\"_n
file write size " &" "(" (`se5') ")" " &  " "(" (`se9') ")" " &  " "(" (`se13') ")" " &  " "(" (`sec5') ")" " &  " "(" (`sec9') ")" " &  " "(" (`sec13') ")" "\\"_n

file write size " No, probably not &" (`b6') "`star6'" " &  " (`b10') "`star10'" " &  " (`b14') "`star14'" " &  "  (`bc6') "`starc6'" " &  "  (`bc10') "`starc10'" " &  "  (`bc14') "`starc14'" "\\"_n
file write size " &" "(" (`se6') ")" " &  " "(" (`se10') ")" " &  " "(" (`se14') ")" " &  " "(" (`sec6') ")" " &  " "(" (`sec10') ")" " &  " "(" (`sec14') ")" "\\"_n

file write size " Yes, maybe &" (`b7') "`star7'" " &  " (`b11') "`star11'" " &  " (`b15') "`star15'" " &  "  (`bc7') "`starc7'" " &  "  (`bc11') "`starc11'" " &  "  (`bc15') "`starc15'" "\\"_n
file write size " &" "(" (`se7') ")" " &  " "(" (`se11') ")" " &  " "(" (`se15') ")" " &  " "(" (`sec7') ")" " &  " "(" (`sec11') ")" " &  " "(" (`sec15') ")" "\\"_n

file write size " Yes, absolutely &" (`b8') "`star8'" " &  " (`b12') "`star12'" " &  " (`b16') "`star16'" " &  "  (`bc8') "`starc8'" " &  "  (`bc12') "`starc12'" " &  "  (`bc16') "`starc16'" "\\"_n
file write size " &" "(" (`se8') ")" " &  " "(" (`se12') ")" " &  " "(" (`se16') ")" " &  " "(" (`sec8') ")" " &  " "(" (`sec12') ")" " &  " "(" (`sec16') ")" "\\"_n

file write size "\midrule" _n
file write size "\bottomrule" _n
file write size "\end{tabular}"
file close size

*End US Survey 2021

*Swedish Survey 2017

use "$root/Data/scb2017.dta", clear 

*Data preparation

gen immitri=1 if f49_01==1 
replace immitri=2 if f49_01==2 | f49_01==3
replace immitri=3 if f49_01==4 
 
label  define immitri 1  "Grew up in Sweden"  2 "Grew up in Europe" 3 "Grew up Outside Europe", replace
label value immitri immitri

gen polint=.
replace polint=1 if f1==1
replace polint=2/3 if  f1==2
replace polint=1/3 if f1==3
replace polint=0 if f1==4
su polint
replace polint=`r(mean)' if polint==.

gen birthyear = real(substr(string(fodarman),1,4))
gen birthmonth = real(substr(string(fodarman),5,2))
gen age = .
replace age = 2017 - birthyear if birthmonth < 6
replace age = 2017 - birthyear - 1 if birthmonth >= 6
gen agesq = age*age

gen gender=kon

gen Sun2000niva_old = .
replace Sun2000niva_old = 1 if inlist(sun2000niva_2014_1,1)
replace Sun2000niva_old = 2 if inlist(sun2000niva_2014_1,2)
replace Sun2000niva_old = 3 if inlist(sun2000niva_2014_2,31,32)
replace Sun2000niva_old = 4 if inlist(sun2000niva_2014_2,33)
replace Sun2000niva_old = 5 if inlist(sun2000niva_2014_2,41,52)
replace Sun2000niva_old = 6 if inlist(sun2000niva_2014_2,53,54,55)
replace Sun2000niva_old = 7 if inlist(sun2000niva_2014_1,6)
 
gen double yearseducation = .
replace yearseducation = 6.6  if Sun2000niva_old == .
replace yearseducation = 7.5  if Sun2000niva_old == 1
replace yearseducation = 9.4  if Sun2000niva_old == 2
replace yearseducation = 11.2 if Sun2000niva_old == 3
replace yearseducation = 12.4 if Sun2000niva_old == 4
replace yearseducation = 14.2 if Sun2000niva_old == 5
replace yearseducation = 17   if Sun2000niva_old == 6
replace yearseducation = 20.4 if Sun2000niva_old == 7

gen unemp=1 if f45==4
recode unemp .=0 if f45!=.
sum unemp 
replace unemp=`r(mean)' if unemp==.

tab r30
tab p27
gen welcome_parliament = .
replace welcome_parliament = 4 if r30 == 1 | p27 == 1
replace welcome_parliament = 3 if r30 == 2 | p27 == 2
replace welcome_parliament = 2 if r30 == 3 | p27 == 3
replace welcome_parliament = 1 if r30 == 4 | p27 == 4
su welcome

gen welcome=1 if welcome_parliament==4
recode welcome .=0

keep if stratum<4

tab welcome immitri, col

tab welcome immitri  [aw=wkNEW], col

***Figure 1 (Upper right panel)***

splitvallabels immitri , length(9)

graph bar (mean) welcome [aw=wkNEW], over(immitri, relabel(`r(relabel)')  label(labsize(small))) ytitle("")scheme(s2mono)  graphregion(fcolor(white) ilcolor(white) lcolor(white))  ///
graphregion(margin(large))  ///
title("Swedish Survey 2017")

  graph save "${root}Output/fig1swe2017.gph", replace
graph export  "${root}Output/fig1swe2017.eps", replace


***Figure 2 (Upper right panel)***

reg welcome i.immitri [aw=wkNEW], robust

estimates store results_1

coefplot results_1, drop(_cons) keep(2.immitri 3.immitri) ///
graphregion(fcolor(white))  plotregion(style(none)) ///
 graphregion(color(white)) xline(0, lcolor(grey)) xscale(range(-0.2 0)) xlabel(-0.2(0.1) 0) ///
plotregion(lcolor(black) lwidth(thin)) legend(off) ciopts(color(black)) mcolor(black) title(Swedish Survey 2017) 

graph save "${root}Output/fig2swe2017.gph", replace
graph export  "${root}Output/fig2swe2017.eps", replace

***Figure A1 (Upper right panel)***


gen jaabsolut=.
gen jakanske=.
gen nejtroligen=.
gen nejabsolut=.

replace jaabsolut=1 if r30==1 
replace jaabsolut=0 if r30==2 | r30==3 | r30==4

replace jakanske=1 if r30==2
replace jakanske=0 if r30==1 | r30==3 | r30==4
 
replace nejtroligen=1 if r30==3
replace nejtroligen=0 if r30==1 | r30==2 | r30==4

replace nejabsolut=1 if r30==4
replace nejabsolut=0 if r30==1 | r30==2 | r30==3
  
splitvallabels immitri , length(9)  

graph bar (mean) jaabsolut jakanske nejtroligen nejabsolut, over(immitri, relabel(`r(relabel)')  label(labsize(small))) ytitle("")scheme(s1mono)  graphregion(fcolor(white) ilcolor(white) lcolor(white))  ///
 graphregion(margin(large))  stack legend(order(1 "Yes, absolutely" 2 "Yes, maybe" 3 "No, probably not" 4 "No, absolutely not")) ///
 title("Swedish Survey 2017")

 graph save "${root}Output/figA1swe2017.gph", replace
graph export  "${root}Output/figA1swe2017.eps", replace

***Figure A.2  (Upper right panel)***

global controls gender age agesq yearseducation unemp polint

reg welcome i.immitri $controls [aw=wkNEW], robust

estimates store results_1

coefplot results_1, drop(_cons) keep(2.immitri 3.immitri) ///
graphregion(fcolor(white))  plotregion(style(none)) ///
 graphregion(color(white)) xline(0, lcolor(grey)) xscale(range(-0.2 0)) xlabel(-0.2(0.1) 0) ///
plotregion(lcolor(black) lwidth(thin)) legend(off) ciopts(color(black)) mcolor(black) title(Swedish Survey 2017) 

graph save "${root}Output/figA2swe2017.gph", replace
graph export  "${root}Output/figA2swe2017.eps", replace

***Table A2 (first three columns)***

foreach i of num 1/9 {
gen member_cs_`i'=1 if r31_0`i'>1 & r31_0`i'<5 
}

egen member_cs=rmax(member_cs_1-member_cs_9)
recode member_cs .=0

foreach i of num 1/9 {
gen active_cs_`i'=1 if r31_0`i'==4 
}

egen active_cs=rmax(active_cs_1-active_cs_9)
recode active_cs .=0

gen hipolint=1 if polint==1
recode hipolint .=0

reg welcome i.immitri##hipolint[aw=wkNEW], robust 
outreg2 using "${root}Output/tabA2.tex", replace 
reg welcome i.immitri##member_cs [aw=wkNEW], robust 
outreg2 using "${root}Output/tabA2.tex", append
reg welcome i.immitri##active_cs [aw=wkNEW], robust 
outreg2 using "${root}Output/tabA2.tex", append 

***Table A.3  (columns three to four)***

gen willingdum=1 if r26==1 | r26==2
replace willingdum=0 if r26==3 | r26==4

reg willingdum welcome [aw=wkNEW], robust 
outreg2 using "${root}Output/tabA3.tex", append  keep(welcome)
reg willingdum welcome $controls [aw=wkNEW], robust 
outreg2 using "${root}Output/tabA3.tex", append   keep(welcome)

***Table A.7 ***

reg welcome i.immitri [aw=wkNEW], robust 
outreg2 using "${root}Output/tabA7.tex", replace  
reg welcome i.immitri $controls [aw=wkNEW] , robust 
outreg2 using "${root}Output/tabA7.tex", append  

***Table A.10 (first two columns) ***

oprobit welcome_parliament i.immitri [aw=wkNEW], robust 
outreg2 using "${root}Output/tabA10.tex", keep(i.immitri) replace  addtext(Controls, No) 
oprobit welcome_parliament i.immitri $controls [aw=wkNEW] , robust 
outreg2 using "${root}Output/tabA10.tex", keep(i.immitri) append  addtext(Controls, Yes) 

***Table A.12 ***

oprobit welcome_parliament i.immitri [aw=wkNEW], robust 
margins, dydx(i.immitri) atmean
di %05.3f  el(r(b),1,5)
foreach x of numlist 5/12 {
local b`x' : di %05.3f el(r(b),1,`x')
local se`x' : di %05.4f el(r(table),2,`x')
if abs(`b`x''/`se`x'') < 1.65 local star`x' 
if abs(`b`x''/`se`x'') >= 1.65 local star`x'  \sym{*}
if abs(`b`x''/`se`x'') >= 1.96 local star`x' \sym{**}
if abs(`b`x''/`se`x'') >= 2.58 local star`x'  \sym{***}

}

oprobit welcome_parliament i.immitri $controls [aw=wkNEW] , robust 

margins, dydx(i.immitri) atmean
foreach x of numlist 5/12 {
local bc`x' : di %05.3f el(r(b),1,`x')
local sec`x' : di %05.4f el(r(table),2,`x')
if abs(`bc`x''/`sec`x'') < 1.65 local star`x' 
if abs(`bc`x''/`sec`x'') >= 1.65 local starc`x'  \sym{*}
if abs(`bc`x''/`sec`x'') >= 1.96 local starc`x' \sym{**}
if abs(`bc`x''/`sec`x'') >= 2.58 local starc`x'  \sym{***}

}

file open size using "${root}Output/tabA12.tex", write replace
file write size "\begin{tabular}{lcccc}" _n
file write size "\toprule" _n
file write size " &  \multicolumn{2}{c}{Without Controls:} & \multicolumn{2}{c}{With Controls:}\\" _n
file write size "  & Grew Up & Grew Up  & Grew Up & Grew Up \\" _n
file write size " Outcome: & in Europe & Outside Europe & in Europe & Outside Europe" _n

file write size "& \cline{2-5}" _n
file write size "\midrule" _n
file write size " No, absolutely not &" (`b5') "`star5'" " &  " (`b9') "`star9'" " &  " (`bc5') "`starc5'" " &  "  (`bc9') "`starc9'"  "\\"_n
file write size " &" "(" (`se5') ")" " &  " "(" (`se9') ")" " &  " "(" (`sec5') ")" " &  " "(" (`sec9') ")"  "\\"_n

file write size " No, probably not &" (`b6') "`star6'" " &  " (`b10') "`star10'" " &  " (`bc6') "`starc6'" " &  "  (`bc10') "`starc10'"  "\\"_n
file write size " &" "(" (`se6') ")" " &  " "(" (`se10') ")" " &  " "(" (`sec6') ")" " &  " "(" (`sec10') ")"  "\\"_n


file write size " Yes, maybe &" (`b7') "`star7'" " &  " (`b11') "`star11'" " &  " (`bc7') "`starc7'" " &  "  (`bc11') "`starc11'"  "\\"_n
file write size " &" "(" (`se7') ")" " &  " "(" (`se11') ")" " &  " "(" (`sec7') ")" " &  " "(" (`sec11') ")"  "\\"_n


file write size " Yes, absolutely &" (`b8') "`star8'" " &  " (`b12') "`star12'" " &  " (`bc8') "`starc8'" " &  "  (`bc12') "`starc12'"  "\\"_n
file write size " &" "(" (`se8') ")" " &  " "(" (`se12') ")" " &  " "(" (`sec8') ")" " &  " "(" (`sec12') ")"  "\\"_n

file write size "\midrule" _n
file write size "\bottomrule" _n
file write size "\end{tabular}"
file close size

*End Swedish Survey 2017

*Swedish Survey 2021

use "$root/Data/som2021.dta", clear 

*Data preparation

gen immitri=1 if f184a<5
replace immitri=2 if f184a==5 | f184a==6
replace immitri=3 if f184a==7
 label  define immitri 1  "Grew up in Sweden"  2 "Grew up in Europe" 3 "Grew up Outside Europe", replace
label value immitri immitri

gen polint=.
replace polint=1 if f22==1
replace polint=0.75 if  f22==2
replace polint=0.5 if f22==3
replace polint=0.25 if f22==4
replace polint=0 if f22==5
su polint
replace polint=`r(mean)' if polint==.

gen age=alder
gen agesq=age*age

gen education=utb
recode education 99=.
sum education 
replace education=`r(mean)' if education==.
replace education=round(education, 1)


gen unemp=1 if f161c==1
recode unemp .=0 if f161c==0
sum unemp 
replace unemp= `r(mean)' if unemp==.

gen immitriabc="c" if immitri==1
replace immitriabc="d" if immitri==2
replace immitriabc="e" if immitri==3

gen jaabsolut=.
gen jakanske=.
gen nejtroligen=.
gen nejabsolut=.

foreach x in c d e {
replace jaabsolut=1 if f121`x'==1 & immitriabc=="`x'"
replace jaabsolut=0 if (f121`x'==2 | f121`x'==3 | f121`x'==4) & immitriabc=="`x'"

}

foreach x in c d e {
replace jakanske=1 if f121`x'==2 & immitriabc=="`x'"
replace jakanske=0 if (f121`x'==1 | f121`x'==3 | f121`x'==4) & immitriabc=="`x'"
}

foreach x in c d e  {
replace nejtroligen=1 if f121`x'==3 & immitriabc=="`x'"
replace nejtroligen=0 if (f121`x'==1 | f121`x'==2 | f121`x'==4) & immitriabc=="`x'"
}

foreach x in c d e  {
replace nejabsolut=1 if f121`x'==4 & immitriabc=="`x'"
replace nejabsolut=0 if (f121`x'==1 | f121`x'==2 | f121`x'==3) & immitriabc=="`x'"
}

gen welcome_parliament=4 if jaabsolut==1
recode welcome_parliament .=3 if jakanske==1
recode welcome_parliament .=2 if nejtroligen==1
recode welcome_parliament .=1 if nejabsolut==1

tab jaabsolut immitri, col


***Figure 1 (Lower panel) ***

preserve

collapse jaabsolut  jakanske nejtroligen nejabsolut, by(immitri)
 
splitvallabels immitri , length(9)

graph bar (mean) jaabsolut, over(immitri, relabel(`r(relabel)')  label(labsize(small))) ytitle("")scheme(s2mono)  graphregion(fcolor(white) ilcolor(white) lcolor(white))  ///
 graphregion(margin(large))  ///
 title("Swedish Survey 2021")
 
  graph save "${root}Output/fig1swe2021.gph", replace
graph export  "${root}Output/fig1swe2021.eps", replace

restore

***Figure 2 (Lower panel) ***

reg jaabsolut i.immitri, robust

estimates store results_1

coefplot results_1, drop(_cons) keep(2.immitri 3.immitri) ///
graphregion(fcolor(white))  plotregion(style(none)) ///
 graphregion(color(white)) xline(0, lcolor(grey)) xscale(range(-0.7 0)) xlabel(-0.7(0.1) 0) ///
plotregion(lcolor(black) lwidth(thin)) legend(off) ciopts(color(black)) mcolor(black) title(Swedish Survey 2021) 

graph save "${root}Output/fig2swe2021.gph", replace
graph export  "${root}Output/fig2swe2021.eps", replace


***Figure A1 (Lower panel)***

preserve

collapse jaabsolut  jakanske nejtroligen nejabsolut, by(immitri)
 
splitvallabels immitri , length(9)

graph bar (mean) jaabsolut jakanske nejtroligen nejabsolut, over(immitri, relabel(`r(relabel)')  label(labsize(small))) ytitle("")scheme(s1mono)  graphregion(fcolor(white) ilcolor(white) lcolor(white))  ///
 graphregion(margin(large))  stack legend(order(1 "Yes, absolutely" 2 "Yes, maybe" 3 "No, probably not" 4 "No, absolutely not")) ///
 title("Swedish Survey 2021")

 graph save "${root}Output/figA1swe2021.gph", replace
graph export  "${root}Output/figA1swe2021.eps", replace

restore

***Figure A2 (Lower panel) ***

global controls sex age agesq i.education unemp polint

reg jaabsolut i.immitri $controls, robust

estimates store results_1

coefplot results_1, drop(_cons) keep(2.immitri 3.immitri) ///
graphregion(fcolor(white))  plotregion(style(none)) ///
 graphregion(color(white)) xline(0, lcolor(grey)) xscale(range(-0.7 0)) xlabel(-0.7(0.1) 0) ///
plotregion(lcolor(black) lwidth(thin)) legend(off) ciopts(color(black)) mcolor(black) title(Swedish Survey 2021) 

graph save "${root}Output/figA2swe2021.gph", replace
graph export  "${root}Output/figA2swe2021.eps", replace

***Table A2 (Last three columns)

gen member_cs=1 if f111==2 | f111==3
recode member_cs .=0 if f111<4
gen active_cs=1 if f111==3
recode active_cs .=0 if f111<4

gen hipolint=1 if polint==1
recode hipolint .=0

reg jaabsolut i.immitri##hipolint, robust 
outreg2 using "${root}Output/tabA2.tex", append 
reg jaabsolut i.immitri##member_cs, robust 
outreg2 using "${root}Output/tabA2.tex", append 
lincom 2.immitri+2.immitri#1.member_cs
reg jaabsolut i.immitri##active_cs, robust 
outreg2 using "${root}Output/tabA2.tex", append 

***Table A3 (Last two columns)***

gen willing=1 if f120==1
replace willing=2/3 if f120==2
replace willing=1/3 if f120==3
replace willing=0 if f120==4

gen willingdum=1 if f120==1 | f120==2
replace willingdum=0 if f120==3 | f120==4

gen welcome=jaabsolut

reg willingdum welcome, robust 
outreg2 using "${root}Output/tabA3.tex", append  keep(welcome)
reg willingdum welcome $controls, robust 
outreg2 using "${root}Output/tabA3.tex", append   keep(welcome)

***Table A4***


foreach x in c d e {
gen jaabsolut`x'=1 if f121`x'==1
replace jaabsolut`x'=0 if f121`x'==2 | f121`x'==3 | f121`x'==4 
}

*column 1

tab jaabsolutc immitri, matcell(freq_matrix) col

forval i = 1/3 {
    local x1`i' = round((freq_matrix[2,`i']/(freq_matrix[1,`i']+freq_matrix[2,`i'])), .01)
}


*column 2

tab jaabsolutd immitri, matcell(freq_matrix) col

forval i = 1/3 {
    local x2`i' = round((freq_matrix[2,`i']/(freq_matrix[1,`i']+freq_matrix[2,`i'])), .01)
}

*column 3

tab jaabsolute immitri, matcell(freq_matrix)  col

forval i = 1/3 {
    local x3`i' = round((freq_matrix[2,`i']/(freq_matrix[1,`i']+freq_matrix[2,`i'])), .01)
}

file open size using "${root}Output/tabA4.tex", write replace
file write size "\begin{tabular}{lccc}" _n
file write size "\toprule" _n
file write size " &  \multicolumn{3}{c}{New politician who grew up in:} \\" _n
file write size "& \cline{2-4}" _n
file write size "  Respondent Group & Sweden & Europe & Outside Europe \\" _n
file write size "\midrule" _n
file write size " Grew Up in Sweden &" (`x11') " &  " (`x21') " &  " (`x31') "\\"_n
file write size " Grew Up in Europe &" (`x12') " &  " (`x22') " &  " (`x32') "\\"_n
file write size " Grew Up Outside Europe &" (`x13') " &  " (`x23') " &  " (`x33') "\\"_n
file write size "\midrule" _n
file write size "\bottomrule" _n
file write size "\end{tabular}"
file close size

***Table A8***

reg jaabsolut i.immitri , robust 
outreg2 using "${root}Output/tabA8.tex", replace  
reg jaabsolut i.immitri $controls  , robust 
outreg2 using "${root}Output/tabA8.tex", append  


***Table A10 (Last two columns)***

oprobit welcome_parliament i.immitri, robust 
outreg2 using "${root}Output/tabA10.tex", keep(i.immitri) append  addtext(Controls, No) 
oprobit welcome_parliament i.immitri $controls, robust 
outreg2 using "${root}Output/tabA10.tex", keep(i.immitri) append  addtext(Controls, Yes)

***Table A13 (Last two columns)***

oprobit welcome_parliament i.immitri, robust 
margins, dydx(i.immitri) atmean
di %05.3f  el(r(b),1,5)
foreach x of numlist 5/12 {
local b`x' : di %05.3f el(r(b),1,`x')
local se`x' : di %05.4f el(r(table),2,`x')
if abs(`b`x''/`se`x'') < 1.65 local star`x' 
if abs(`b`x''/`se`x'') >= 1.65 local star`x'  \sym{*}
if abs(`b`x''/`se`x'') >= 1.96 local star`x' \sym{**}
if abs(`b`x''/`se`x'') >= 2.58 local star`x'  \sym{***}

}


oprobit welcome_parliament i.immitri $controls, robust 
margins, dydx(i.immitri) atmean
foreach x of numlist 5/12 {
local bc`x' : di %05.3f el(r(b),1,`x')
local sec`x' : di %05.4f el(r(table),2,`x')
if abs(`bc`x''/`sec`x'') < 1.65 local star`x' 
if abs(`bc`x''/`sec`x'') >= 1.65 local starc`x'  \sym{*}
if abs(`bc`x''/`sec`x'') >= 1.96 local starc`x' \sym{**}
if abs(`bc`x''/`sec`x'') >= 2.58 local starc`x'  \sym{***}

}

file open size using "${root}Output/tabA13.tex", write replace
file write size "\begin{tabular}{lcccc}" _n
file write size "\toprule" _n
file write size " &  \multicolumn{2}{c}{Without Controls:} & \multicolumn{2}{c}{With Controls:}\\" _n
file write size "  & Grew Up & Grew Up  & Grew Up & Grew Up \\" _n
file write size " Outcome: & in Europe & Outside Europe & in Europe & Outside Europe" _n

file write size "& \cline{2-5}" _n
file write size "\midrule" _n
file write size " No, absolutely not &" (`b5') "`star5'" " &  " (`b9') "`star9'" " &  " (`bc5') "`starc5'" " &  "  (`bc9') "`starc9'"  "\\"_n
file write size " &" "(" (`se5') ")" " &  " "(" (`se9') ")" " &  " "(" (`sec5') ")" " &  " "(" (`sec9') ")"  "\\"_n

file write size " No, probably not &" (`b6') "`star6'" " &  " (`b10') "`star10'" " &  " (`bc6') "`starc6'" " &  "  (`bc10') "`starc10'"  "\\"_n
file write size " &" "(" (`se6') ")" " &  " "(" (`se10') ")" " &  " "(" (`sec6') ")" " &  " "(" (`sec10') ")"  "\\"_n


file write size " Yes, maybe &" (`b7') "`star7'" " &  " (`b11') "`star11'" " &  " (`bc7') "`starc7'" " &  "  (`bc11') "`starc11'"  "\\"_n
file write size " &" "(" (`se7') ")" " &  " "(" (`se11') ")" " &  " "(" (`sec7') ")" " &  " "(" (`sec11') ")"  "\\"_n


file write size " Yes, absolutely &" (`b8') "`star8'" " &  " (`b12') "`star12'" " &  " (`bc8') "`starc8'" " &  "  (`bc12') "`starc12'"  "\\"_n
file write size " &" "(" (`se8') ")" " &  " "(" (`se12') ")" " &  " "(" (`sec8') ")" " &  " "(" (`sec12') ")"  "\\"_n

file write size "\midrule" _n
file write size "\bottomrule" _n
file write size "\end{tabular}"
file close size

*End Swedish Survey 2021

log close






